package com.github.tommas.admintpl.common;

public class CommonResult<T> {

	/** 代码 */
	private long code;

	/** 消息 */
	private String message;

	/** 数据 */
	private T data;

	public CommonResult(long code, String message) {
		this(code, message, null);
	}

	/**
	 * @param code
	 * @param message
	 * @param data
	 */
	public CommonResult(long code, String message, T data) {
		this.code = code;
		this.message = message;
		this.data = data;
	}

	/**
	 * 成功返回结果
	 *
	 */
	public static <T> CommonResult<T> success() {
		return new CommonResult<T>(CommonResultCode.SUCCESS.getCode(), CommonResultCode.SUCCESS.getMessage(), null);
	}

	/**
	 * 成功返回结果
	 *
	 * @param data 数据
	 */
	public static <T> CommonResult<T> success(T data) {
		return new CommonResult<T>(CommonResultCode.SUCCESS.getCode(), CommonResultCode.SUCCESS.getMessage(), data);
	}

	/**
	 * 成功返回结果
	 *
	 * @param message 消息
	 * @param data    数据
	 */
	public static <T> CommonResult<T> success(String message, T data) {
		return new CommonResult<T>(CommonResultCode.SUCCESS.getCode(), message, data);
	}

	/**
	 * 失败返回结果
	 * 
	 */
	public static <T> CommonResult<T> failed() {
		return new CommonResult<T>(CommonResultCode.FAILED.getCode(), CommonResultCode.FAILED.getMessage(), null);
	}

	/**
	 * 失败返回结果
	 * 
	 * @param data 数据
	 */
	public static <T> CommonResult<T> failed(T data) {
		return new CommonResult<T>(CommonResultCode.FAILED.getCode(), CommonResultCode.FAILED.getMessage(), data);
	}

	/**
	 * 失败返回结果
	 * 
	 * @param message 消息
	 * @param data    数据
	 */
	public static <T> CommonResult<T> failed(String message, T data) {
		return new CommonResult<T>(CommonResultCode.FAILED.getCode(), message, data);
	}

	/**
	 * @return the code
	 */
	public long getCode() {
		return code;
	}

	/**
	 * @param code the code to set
	 */
	public void setCode(long code) {
		this.code = code;
	}

	/**
	 * @return the message
	 */
	public String getMessage() {
		return message;
	}

	/**
	 * @param message the message to set
	 */
	public void setMessage(String message) {
		this.message = message;
	}

	/**
	 * @return the data
	 */
	public T getData() {
		return data;
	}

	/**
	 * @param data the data to set
	 */
	public void setData(T data) {
		this.data = data;
	}

}
